package org.MyToolsProject.redis;

import redis.clients.jedis.Jedis;

public class RedisClearUtil {
    private static final String HOST = "127.0.0.1";
    private static final String PASSWORD = "123456"; // Redis认证密码
    private static final int PORT = 16379;
    private static final int DB_INDEX = 2; // 要清空的数据库编号

    public static void main(String[] args) {
        //flushDb();
        try(Chan chan = new Chan()) {
            chan.print();
        }catch (Exception e){

        }

    }

    public static void flushDb() {
        Jedis jedis = new Jedis(HOST, PORT);
        try {
            jedis.auth(PASSWORD);
            jedis.select(DB_INDEX); // 选择指定数据库
            jedis.flushDB(); // 清空当前数据库
            System.out.println("成功清空数据库" + DB_INDEX);
        } finally {
            jedis.close(); // 关闭连接
        }
    }


}
